#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod=998244353;
int qpow(int x,int n)
{
    int ret=1;
    while(n)
    {
        if(n&1)ret=ret*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return ret;
}
struct node 
{
    int x,c,i;
    bool operator<(const node &other) const {
            if(x!=other.x)return x > other.x;
            else return  c>other.c;
    }
};
void solve()
{
    int n;
    cin>>n;
    vector<node>p(n+1),q(n+1);
    for(int i=0;i<n;i++)cin>>p[i].x,p[i].c=0,p[i].i=i;
    for(int i=0;i<n;i++)cin>>q[i].x,q[i].c=1,q[i].i=i;
    set<node> s;
    //priority_queue<node> s;
    for(int i=0;i<n;i++)
    {
        s.insert(p[i]);
        s.insert(q[i]);
        vector<node>tmp;
        for(auto x:s)
        {
            if(x.x==(*s.begin()).x)tmp.push_back(x);
            else break;
        }
        int mx=0;
        for(auto y:tmp)
        {
            if(y.c==0)mx=max(mx,q[i-y.i].x);
            if(y.c==1) mx=max(mx,p[i-y.i].x);
        }
        cout<<(qpow(2, (*s.begin()).x)+qpow(2, mx))%mod<<" ";
        tmp.clear();
    }
    cout<<endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T=1;
    cin>>T;
    while(T--)
    {
       solve();
    }
    return 0;
}